package com.aiguigu.LeetCode;

import com.sun.javafx.collections.MappingChange;

import java.util.HashMap;
import java.util.Map;

public class twosum {
    public static void main(String[] args) {
        int[]nums = {3,2,4}; int target = 6;
        int [] result= twusum(nums,target);
        for (int i : result) {
            System.out.print(i+" ");
        }
    }

    public static int[] twusum(int []nums,int target){
        Map<Integer,  Integer> map = new HashMap();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target-nums[i])){
                return new int[]{map.get(target-nums[i]),i};
            }
            map.put(nums[i],i);
        }


        return new int[]{};
    }
}
